package com.example.smartlearning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartlearning.dao.AnswerDao;
import com.example.smartlearning.dao.BookDao;
import com.example.smartlearning.entity.AnswerEntity;
import com.example.smartlearning.entity.BookEntity;
import com.example.smartlearning.entity.ResultEntity;
import com.example.smartlearning.service.AnswerService;
import com.example.smartlearning.service.BookService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements BookService {

    private static final Logger logger = LoggerFactory.getLogger(BookServiceImpl.class);//日志。getLogger需要传入当前的类名

    @Resource
    BookDao bookDao;

    /**
     * 根据id查询书籍信息
     *
     * @param bookId bookId
     * @return 返回
     */
    @Override
    public String selectBookById(int bookId) {
        try {
            return ResultEntity.success(bookDao.selectBookById(bookId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 根据id查询书籍内容
     *
     * @param bookId bookId
     * @return 返回
     */
    @Override
    public String selectAllByContent(int bookId) {
        try {
            return ResultEntity.success(bookDao.selectAllByContent(bookId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }
}
